package com.own.component.util.excel.model;

import lombok.Getter;
import lombok.Setter;

/**
 * Coordinate 坐标信息
 *
 * @author chenxueli
 * @date 2022-06-15 03:14:15
 */
@Getter
@Setter
public class Coordinate {

    private int x;

    private int y;

    public Coordinate() {
        refresh(1, 1);
    }

    public Coordinate(int x, int y) {
        refresh(x, y);
    }

    /**
     * 生成key
     *
     * @param x x坐标
     * @param y y坐标
     * @return key
     */
    public static String buildKey(int x, int y) {
        return x + "_" + y;
    }

    public String key() {
        return buildKey(this.x, this.y);
    }

    /**
     * 增加坐标信息
     *
     * @param x x坐标
     * @param y y坐标
     */
    public void add(int x, int y) {
        this.x += x;
        this.y += y;
    }

    /**
     * 刷新坐标信息
     *
     * @param x x坐标
     * @param y y坐标
     */
    public void refresh(int x, int y) {
        this.x = x;
        this.y = y;
    }

    /**
     * 设置最大的信息
     *
     * @param coordinate 坐标信息
     */
    public void setMax(Coordinate coordinate) {
        if (this.x < coordinate.x) {
            this.x = coordinate.x;
        }
        if (this.y < coordinate.y) {
            this.y = coordinate.y;
        }
    }

    /**
     * 设置最小的信息
     *
     * @param coordinate 坐标信息
     */
    public void setMin(Coordinate coordinate) {
        if (this.x > coordinate.x) {
            this.x = coordinate.x;
        }
        if (this.y > coordinate.y) {
            this.y = coordinate.y;
        }
    }

}
